

const isMobile =  () => {
    let userAgentInfo = navigator.userAgent;

    let mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];

    let mobile_flag = false;

    //根据userAgent判断是否是手机
    for (let v = 0; v < mobileAgents.length; v++) {
      if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
        mobile_flag = true;
        break;
      }
    }

    let screen_width = window.screen.width;
    let screen_height = window.screen.height;

    //根据屏幕分辨率判断是否是手机
    if (screen_width < 500 && screen_height < 800) {
      mobile_flag = true;
    }

    return mobile_flag;
  }

  const   toTree=(data) =>{
    data.forEach(function(item) {
      delete item.children
    })

    let map = {}
    data.forEach(function(item) {
      map[item.id] = item
    })
    let val = []
    data.forEach(function(item) {
      let parent = map[item.pid]
      if (parent) {
        (parent.children || (parent.children = [])).push(item)
      } else {
        val.push(item)
      }
    })
    return val
  }



  export  {
      isMobile,
      toTree,
      
  }